import CommonConfig from "./CommonConfig";
import AdManager from "./AdManager";
import WechatTool from "./WechatTool";
import PlatUtils from "./PlatUtils";
import OppoTool from "./OppoTool";
import YZ_Tool_Baidu from "./YZ_Tool_Baidu";

const { ccclass, property } = cc._decorator;

export let utils: Utils = null;

@ccclass
export default class Utils extends cc.Component {

    @property(CommonConfig)
    config: CommonConfig = null;

    public adManager: AdManager = null;

    _wechatTool: WechatTool = null;
    public get wechatTool() {
        if (!this._wechatTool) {
            cc.log("wechat tool is null");
        }

        return this._wechatTool;
    }

    _oppoTool: OppoTool = null;
    public get oppoTool() {
        if (!this._oppoTool) {
            cc.log("oppo tool is null");
        }
        return this._oppoTool;
    }

    _tool_Baidu:YZ_Tool_Baidu = null;
    public get Tool_Baidu(){
        if(!this._tool_Baidu){
            cc.log("tool baidu is null");
        }
        return this._tool_Baidu;
    }

    onLoad() {
        cc.game.addPersistRootNode(this.node);
        utils = this;

        this.initTools();

        this.adManager = new AdManager();
        this.adManager.Init();

        if(this._oppoTool){
            this._oppoTool.hideDefaultLoadingPage();
        }
    }

    start() {
    }

    initTools() {
        if (PlatUtils.IsWechat) {
            this._wechatTool = new WechatTool();
            this._wechatTool.init();
        } else if (PlatUtils.IsOPPO) {
            this._oppoTool = new OppoTool();
            this._oppoTool.init();
        }else if(PlatUtils.IsBaidu){
            this._tool_Baidu = new YZ_Tool_Baidu();
            this._tool_Baidu.init();
        }
    }

}
